#region Using Statements
using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion

namespace SkyBurner.Screens
{
    public class SkyBurnerScreenInGame : SkyBurnerScreenBase, IGUIManagerEvent
    {
        private SkyBurnerWorld m_tcSkyBurnerWorld;
        private String m_gameLevelFile;
        private PostScreenEffectMotionBlur m_postScreenEffectMotionBlur;

        public String GameLevelFile
        {
            get { return m_gameLevelFile; }
            set { m_gameLevelFile = value; }
        }

        public SkyBurnerScreenInGame(BaseGame game, ScreenManager pScreenManager, int nScreenID, bool bActive)
            : base(game, pScreenManager, nScreenID, bActive)
        {
            m_gameLevelFile = "";
            m_postScreenEffectMotionBlur = new PostScreenEffectMotionBlur(m_Game, 0.3f);
        }

        void IGUIManagerEvent.OnGUIPopupClick(Object pSender, GUIButtons pButton)
        {
            m_Game.Pause = false;
            m_Game.GUIManager.ClosePopup();
            
            switch (pButton)
            {
                case GUIButtons.btOK:
                    {                        
                        m_tcSkyBurnerWorld = null;
                        m_screenManager.ActivateScreen(SkyBurnerScreenID.sbs_Main);

                        break;
                    }

                case GUIButtons.btCancel:
                    {
                        break;
                    }
            }
        }

        public override void Activate()
        {
            base.Activate();

            m_tcSkyBurnerWorld = new SkyBurnerWorld(m_Game);
            m_tcSkyBurnerWorld.Load(m_gameLevelFile);

            m_Game.PostScreenEffectsManager.AddPostScreenEffect(m_postScreenEffectMotionBlur);
        }

        public override void Deactivate()
        {
            base.Deactivate();

            m_Game.UserInputState.Reset();
            m_Game.PostScreenEffectsManager.RemovePostScreenEffect(m_postScreenEffectMotionBlur);
        }

        public override void Update(GameTime gameTime, Camera pActiveCamera)
        {
            if (m_Game.UserInputState.IsUserAction(UserAction.Back))
            {
                // pause game and show popup...
                m_Game.Pause = true;
                m_Game.GUIManager.ShowPopup(new Vector2(100.0f, 150.0f), new Rectangle(0, 0, 600, 240), m_Game.ContentManager.Load<Texture2D>("Data\\Textures\\GUI\\PopupQuitGame"), this);
            }
           
            if (m_tcSkyBurnerWorld != null)
                m_tcSkyBurnerWorld.Update(gameTime);
        }

        public override void Draw(GameTime gameTime, Camera pActiveCamera)
        {
            if (m_tcSkyBurnerWorld != null)
                m_tcSkyBurnerWorld.Draw(gameTime);
        }
    }
}
